/*
 * _cmd.java
 *
 * Created on 14 Март 2008 г., 23:40
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package xmppbot.funcs;

import com.trilead.ssh2.Connection;
import com.trilead.ssh2.Session;
import com.trilead.ssh2.StreamGobbler;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import xmppbot.parse.Exec;
import xmppbot.parse.SessionPacket;
import xmppbot.parse.options;

/**
 *
 * @author lian
 */
public class _cmd extends sessionfuncs {
    Connection conn = null;
    int n = 0;
    
    /** Creates a new instance of _cmd */
    public _cmd() {
        super();
    }
    
    @Override
    public String process(options opts) {
          String ansver = "";
          super.openSession(opts);
          ansver("ans");
////////                if (exe.session) {
////////
////////                } else {
////////
////////                }
//        String cmd = null;
//        if (exe.postMsg != null) {
//            try {
//                cmd = exe.postMsg;
//                Connection conn = new Connection("11.1.1.5");
//                conn.connect();
//                conn.authenticateWithPassword("root", "");
//                Session sess = conn.openSession();
//                sess.execCommand(cmd);
//                InputStream stdout = new StreamGobbler(sess.getStdout());
//                BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
//                while (true) {
//                    String line = null;
//                    line = br.readLine();
//                    if (line == null)
//                        break;
//                    ansver = ansver + "\n" + line;
//                }
//                sess.close();
//                conn.close();
//            } catch (IOException ex) {
//                ex.printStackTrace();
//            }
//        }
        return ansver;
    }
    
    @Override
    public void session(options opts) {
        ansver(Integer.toString(n++));
        ansver(opts.getMsg());
    }
    
    @Override
    public void openSession(options opts) {
        n = 5;
        super.openSession(opts);
    }

    @Override
    public void close() {
        ansver("work!");
    }
}
